﻿@using ETD.Common.Extension;
@using ETD.WebOrganization.Libs.Helper;
@using ETD.WinClient.Config;
@using ETD.Domain.EnumModels;
@using ETD.Domain.WebModels;
@using ETD.Common;
@model ETD.WebOrganization.Areas.Web.Models.SelfCenter.ChangePasswordModel

<style>
    .weui-center {
        text-align: center;
    }

    .menu_item_left_icon {
        width: 22px !important;
        margin-right: 8px !important;
        display: block;
    }

    .WpSecurityTableLink {
    }

    .weui-form-preview__ft {
        margin-top: 45px;
    }

    .weui-btn_primary {
        background-color: #4dd1c1;
        width: 300px;
    }
</style>
<div class="weui-panel">


    <div class="weui-cells">

        <div class="weui-cell ">
            <div class="weui-cell__hd"><label class="weui-label">帐号 <span style="color:red;"></span></label></div>
            <div class="weui-cell__bd"><input class="weui-input" id="txtUsername" name="txtUsername" type="text" placeholder="帐号" maxlength="50" readonly disabled value="@Model.UserInfo.UserName" /></div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">旧密码 <span style="color:red;">*</span></label></div>
            <div class="weui-cell__bd"><input class="weui-input" type="password" id="txtPassword" name="txtPassword" maxlength="20" placeholder="旧密码"></div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">新密码 <span style="color:red;">*</span></label></div>
            <div class="weui-cell__bd"><input class="weui-input" type="password" id="txtNewPassword" name="txtNewPassword" maxlength="20" placeholder="新密码"></div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">确认密码 <span style="color:red;">*</span></label></div>
            <div class="weui-cell__bd"><input class="weui-input" type="password" id="txtConfirmPassword" name="txtConfirmPassword" maxlength="20" placeholder="确认密码"></div>
        </div>
    </div>

    <div class="weui-btn-area">
        <a class="weui-btn weui-btn_primary" id="btnSubmit">保存</a>
    </div>
</div>

@section ScriptSection{
    <script>
        $(function () {
            $("#btnSubmit").click(PageObj.onBtnSubmitClick);
        });
        var PageObj = {};
        PageObj.onBtnSubmitClick = function () {
            var checkFormResult = PageObj.checkForm();
            if (!checkFormResult) return;
            PageObj.submit();
        }
        PageObj.checkForm = function () {

            var password = $("#txtPassword").val();
            if (StringHelper.isNullOrEmpty(password)) {
                $.toptip('请输旧密码', 'warning');
                return false;
            }
            var newPassword = $("#txtNewPassword").val();
            if (StringHelper.isNullOrEmpty(newPassword)) {
                $.toptip('请输新密码', 'warning');
                return false;
            }
            if (newPassword.length < 6) {
                $.toptip('新密码必须大于6位', 'warning');
                return false;
            }
            var confirmPassword = $("#txtConfirmPassword").val();
            if (newPassword != confirmPassword) {
                $.toptip('确认密码和新密码不一致', 'warning');
                return false;
            }
            return true;
        }
        PageObj.submit = function () {
            var paras = {};

            paras.Password = $("#txtPassword").val().trim();
            paras.NewPassword = $("#txtNewPassword").val().trim();

            console.log(JSON.stringify(paras));

            ajaxPost("@Url.ActionTS("ChangePassword", "SelfCenter")", paras, function (data) {
                console.log(data);
                if (data.Status) {
                    $.toast(data.Info);
                    window.setTimeout(function () { window.location.href = "@Url.Action("Home", "Home")"; }, 2000);
                } else {
                    $.toast(data.Info, "forbidden");
                }
            });
        }
    </script>
}